package com.item.yxlottery.yxlottery.base;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/11/16 08:59
 * @文件描述    activity的基类
 *------------------------------
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.item.yxlottery.yxlottery.R;
import com.zhy.autolayout.AutoFrameLayout;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

public abstract class BaseActivity extends AppCompatActivity {

    private ImageButton mIbActionbarLeft;//自定义Actionbar左边按钮
    private TextView mTvActionBarTitle;//自定义Actionbar中间标题
    private ImageButton mIbActionbarRight;//自定义Actionbar右边按钮
    private AutoRelativeLayout mLayoutActionbar;//自定义Actionbar主体
    private AutoFrameLayout mAflContent;//主显示内容区域

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBeforSteupView();
        setContentView(R.layout.activity_base);
        getSupportActionBar().hide();//隐藏系统自身的标题栏
        mIbActionbarLeft = (ImageButton) findViewById(R.id.ib_actionbar_left);
        mTvActionBarTitle = (TextView) findViewById(R.id.tv_actionbar_title);
        mIbActionbarRight = (ImageButton) findViewById(R.id.ib_actionbar_right);
        mLayoutActionbar = (AutoRelativeLayout) findViewById(R.id.layout_base_actionbar);
        mAflContent = (AutoFrameLayout) findViewById(R.id.afl_base_content);
        setCustomActionBar(mIbActionbarLeft, mTvActionBarTitle, mIbActionbarRight, mLayoutActionbar);

        AutoLinearLayout.LayoutParams layoutParams = new AutoLinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        mAflContent.removeAllViews();
        mAflContent.addView(initView(), layoutParams);
        initData();
        initEvent();
    }

    //在setContentView之前的设置
    protected void setBeforSteupView() {

    }

    /* 设置自定义Actionbar显示(参数:1.左边按钮;2.中间显示标题;3.右边按钮;4.自定义actionbar本身)  */
    protected abstract void setCustomActionBar(ImageButton ibActionbarLeft, TextView tvActionBarTitle, ImageButton ibActionbarRight, AutoRelativeLayout layoutActionbar);

    /* 初始化控件 */
    protected abstract View initView();

    /* 初始化数 */
    protected abstract void initData();

    /* 事件处理 */
    protected abstract void initEvent();

    public void gotoActivity(Class<? extends Activity> activityClass)
    {
        startActivity(new Intent(this, activityClass));
    }

}
